package wint.dal;

import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.SQLException;

import javax.sql.DataSource;

import wint.dal.config.DataSourceConfigChangeListener;
import wint.dal.config.DataSourceManager;
import wint.dal.config.datasource.DataSourceConfig;

public class XDataSource implements DataSource, DataSourceConfigChangeListener {
	
	private DataSourceManager dataSourceManager;

	public void init() {
		dataSourceManager.addDataSourceConfigChangeListener(this);
	}
	
	public void onDataSourceConfigChange(DataSourceConfig newDataSourceConfig) {
		
	}
	
	private DataSource lazyDataSource;

	public PrintWriter getLogWriter() throws SQLException {
		return lazyDataSource.getLogWriter();
	}

	public void setLogWriter(PrintWriter out) throws SQLException {
		lazyDataSource.setLogWriter(out);
	}

	public void setLoginTimeout(int seconds) throws SQLException {
		lazyDataSource.setLoginTimeout(seconds);
	}

	public int getLoginTimeout() throws SQLException {
		return lazyDataSource.getLoginTimeout();
	}

	public <T> T unwrap(Class<T> iface) throws SQLException {
		return lazyDataSource.unwrap(iface);
	}

	public boolean isWrapperFor(Class<?> iface) throws SQLException {
		return lazyDataSource.isWrapperFor(iface);
	}

	public Connection getConnection() throws SQLException {
		return lazyDataSource.getConnection();
	}

	public Connection getConnection(String username, String password) throws SQLException {
		return lazyDataSource.getConnection(username, password);
	}

	public DataSourceManager getDataSourceManager() {
		return dataSourceManager;
	}

	public void setDataSourceManager(DataSourceManager dataSourceManager) {
		this.dataSourceManager = dataSourceManager;
	}
}
